/*
 * @Author: anxia.ack anchenkai@come-future.com
 * @Date: 2025-04-13 21:23:50
 * @LastEditors: anxia.ack anchenkai@come-future.com
 * @LastEditTime: 2025-04-20 14:53:52
 * @FilePath: /free-learning-front/src/api/course.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { get, post } from "@/utils/request";
import type { CourseReview } from "./review";

const COURSE_BASE_URL = "/api/v1/course";

export interface CourseInfo {
  id: number; // 主键ID
  title: string; // 课程标题
  description?: string; // 课程描述，可选字段
  consultantId: number; // 咨询师ID
  consultantName: string; // 咨询师姓名
  categoryId: number; // 课程分类ID
  categoryName: string; // 课程分类名称
  coverImage?: string; // 课程封面图URL，可选字段
  content?: string; // 课程介绍，可选字段
  startTime?: string; // 开课时间，可选字段
  createTime: Date; // 创建时间
  updateTime: Date; // 更新时间
  isRecommend: number; // 是否推荐
}
export interface CourseInfoVO extends CourseInfo {
  chaptersNum: number; // 章节数量
  favoriteCount: number; // 用户收藏数
  reviewCount: number; // 收到的评论数量
  likeCount: number; // 点赞数量
  score: number; // 评分
}
// 推荐课程列表
export const requestRecommendCourseList = (): Promise<CourseInfoVO[]> => {
  return get<any>(`${COURSE_BASE_URL}/recommend/list`);
};

// 课程列表
export const requestCoursePublishList = (
  typeId?: string
): Promise<CourseInfoVO[]> => {
  return post<any>(`${COURSE_BASE_URL}/allPublish/list`, {
    categoryId: typeId,
  });
};

export const requestCourseInfo = (id: string): Promise<CourseInfoVO> => {
  return get<CourseInfoVO>(`${COURSE_BASE_URL}/info/${id}`);
};

export interface CourseReviewVO extends CourseReview {
  isLike: boolean;
}
export const queryComment = (
  params: PageQuery & { courseId: number,sortKey:"hotSort" | "newSort" }
): Promise<PageResult<CourseReviewVO[]>> => {
  return get(`${COURSE_BASE_URL}/queryComment`, params);
};
export const queryPublishComment = (
  params: PageQuery & { courseId: number,sortKey:"hotSort" | "newSort" }
): Promise<PageResult<CourseReviewVO[]>> => {
  return get(`${COURSE_BASE_URL}/queryPublishComment`, params);
};
